home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / slack-docs / base / setclock < prev    next >
Text File  |  1996-05-09  |  1KB  |  40 lines

  1. #!/bin/sh
  2. # setclock: set the system's CMOS and system times from the network.
  3. # Copyright 1994-6 John A. Phillips - john@linux.demon.co.uk
  4. # usage: setclock [GMT|local]
  5.  
  6. # Set the zone for the CMOS clock if specified, or use the default.
  7. zone=${1:-GMT}
  8.  
  9. # Assign the servers to set the system date and time.  If you use more 
  10. # than one time server it takes longer but you get more reliability.
  11. # servers="ntp.demon.co.uk"
  12. servers="ntp.demon.co.uk ntp1.demon.co.uk ntp2.demon.co.uk"
  13.  
  14. # Assign a temporary file.
  15. tmpfile=/tmp/demon.time.$$
  16.  
  17. # Check for valid zones.
  18. if [ $zone != "GMT" -a $zone != "local" ]; then
  19.     echo "usage: setclock [GMT|local]"
  20.     exit 1
  21. fi
  22.  
  23. # Make sure we clean up on any exit
  24. trap "rm -f $tmpfile" 0
  25.  
  26. # Set the system date and time from the list of servers.
  27. /usr/sbin/netdate $servers >$tmpfile 2>&1
  28.  
  29. # Set the system's CMOS clock from the system date and time.
  30. if [ $zone = "local" ]; then
  31.     /sbin/clock -w >>$tmpfile 2>&1
  32. else
  33.     /sbin/clock -u -w >>$tmpfile 2>&1
  34. fi
  35.  
  36. # Show the date and time.
  37. /bin/echo ""
  38. /bin/cat $tmpfile
  39. /bin/echo ""
  40.